<html>
<head>
<base href="<?php echo XXF_HTTP?>" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="renderer" content="ie-comp">
<title>报名</title>
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<link rel="stylesheet" type="text/css" href="css/xxf.css" />
<style type="text/css">
*{margin:0px;padding:3px;
}
</style>
<script language="vbscript">
' 端口设置
SUB SetPortBtn_OnClick()
  Dim str 
  SynIDCard1.Port = Document.Form1.Port.Value
  str = "端口设置为：" + Document.Form1.Port.Value
  MsgBox str
END SUB
' 初始化设置
SUB InitBtn_OnClick()
  Dim str 
  str = SynIDCard1.Init
  MsgBox str
END SUB
' 读IC卡信息
SUB ReadCardBtn_OnClick()
SynIDCard1.Port = Document.Form1.Port.Value
  Dim str, strArray
  str = ""
  str = SynIDCard1.ReadCard
Document.Form1.RETSTR.Value = str
Document.Form1.puname.value = SynIDCard1.NameL
Document.Form1.minzu.value = SynIDCard1.NationL
Document.Form1.idcard.value = SynIDCard1.CardNo
'Document.Form1.Activity.Value = SynIDCard1.Activity
'Document.Form1.Activity2.value = SynIDCard1.ActivityL
'Document.Form1.Police.Value = SynIDCard1.Police
Document.Form1.home.Value = SynIDCard1.Address
Document.Form1.tpic.value = left(SynIDCard1.PhotoName,len(SynIDCard1.PhotoName)-7)
getuppic()
END SUB
SUB ReadSAMIDBtn_OnClick()
  Dim str
  str = ""
  str = SynIDCard1.ReadSAMID
  MsgBox str
END SUB
//end hiden-->
</script>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script type="text/javascript" src="js/jquery.xxfset.js?r=<?php echo rand(); ?>"></script>
<script>
    var Wi = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 ];    // 加权因子   
	var ValideCode = [ 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2 ];            // 身份证验证位值.10代表X   
	function IdCardValidate(idCard) { 
		idCard = trim(idCard.replace(/ /g, ""));               //去掉字符串头尾空格                     
		if (idCard.length == 15) {   
			return isValidityBrithBy15IdCard(idCard);       //进行15位身份证的验证    
		} else if (idCard.length == 18) {   
			var a_idCard = idCard.split("");                // 得到身份证数组   
			if(isValidityBrithBy18IdCard(idCard)&&isTrueValidateCodeBy18IdCard(a_idCard)){   //进行18位身份证的基本验证和第18位的验证
				return true;   
			}else {   
				return false;   
			}   
		} else {   
			return false;   
		}   
	}   
	/**  
	 * 判断身份证号码为18位时最后的验证位是否正确  
	 * @param a_idCard 身份证号码数组  
	 * @return  
	 */  
	function isTrueValidateCodeBy18IdCard(a_idCard) {   
		var sum = 0;                             // 声明加权求和变量   
		if (a_idCard[17].toLowerCase() == 'x') {   
			a_idCard[17] = 10;                    // 将最后位为x的验证码替换为10方便后续操作   
		}   
		for ( var i = 0; i < 17; i++) {   
			sum += Wi[i] * a_idCard[i];            // 加权求和   
		}   
		valCodePosition = sum % 11;                // 得到验证码所位置   
		if (a_idCard[17] == ValideCode[valCodePosition]) {   
			return true;   
		} else {   
			return false;   
		}   
	}   
	/**  
	  * 验证18位数身份证号码中的生日是否是有效生日  
	  * @param idCard 18位书身份证字符串  
	  * @return  
	  */  
	function isValidityBrithBy18IdCard(idCard18){   
		var year =  idCard18.substring(6,10);   
		var month = idCard18.substring(10,12);   
		var day = idCard18.substring(12,14);   
		var temp_date = new Date(year,parseFloat(month)-1,parseFloat(day));   
		// 这里用getFullYear()获取年份，避免千年虫问题   
		if(temp_date.getFullYear()!=parseFloat(year)   
			  ||temp_date.getMonth()!=parseFloat(month)-1   
			  ||temp_date.getDate()!=parseFloat(day)){   
				return false;   
		}else{   
			return true;   
		}   
	}   
	  /**  
	   * 验证15位数身份证号码中的生日是否是有效生日  
	   * @param idCard15 15位书身份证字符串  
	   * @return  
	   */  
	  function isValidityBrithBy15IdCard(idCard15){   
		  var year =  idCard15.substring(6,8);   
		  var month = idCard15.substring(8,10);   
		  var day = idCard15.substring(10,12);   
		  var temp_date = new Date(year,parseFloat(month)-1,parseFloat(day));   
		  // 对于老身份证中的你年龄则不需考虑千年虫问题而使用getYear()方法   
		  if(temp_date.getYear()!=parseFloat(year)   
				  ||temp_date.getMonth()!=parseFloat(month)-1   
				  ||temp_date.getDate()!=parseFloat(day)){   
					return false;   
			}else{   
				return true;   
			}   
	  }   
	//去掉字符串头尾空格   
	function trim(str) {   
		return str.replace(/(^\s*)|(\s*$)/g, "");   
	}  
</script>
<script type="text/javascript">
$(function(){
//	var xxf_array=[<?php // echo gconf('kuangunit', 'kuang');?>];
// 	$("#workunit").autocomplete(xxf_array,{
// 		max:10
// 	});
	var xxf_array2=[<?php echo gconf('kuangunit', 'address');?>];
	$("#address").autocomplete(xxf_array2,{
		max:10
	});
	$("#serch").click(function(){
		getxueyuaninfo();
	});
});
function getxueyuaninfo(){
	$idcard=$("#idcard").val();
	if($idcard.length==18){
		$.post("pxy_bm",{
			type:"serch",idcard:$idcard
		},function(data){
			if(data==0){
				$.xalert("没有查询到历史记录！");
			}else{
				var xydata= (new Function("return " + data))();
				$("#puname").val(xydata.puname);
				$("#minzu").val(xydata.minzu);
				$("#zhiwu").val(xydata.zhiwu);
				$("#mphone").val(xydata.mphone);
				$("#zhicheng").val(xydata.zhicheng);
				$("#workunit").val(xydata.workunit);
				$("#zhuanye").val(xydata.zhuanye);
				$("#address").val(xydata.address);
				$("#wenhua").val(xydata.wenhua);
				$("#zhengshuid").val(xydata.zhengshuid);
				$("#beizhu").val(xydata.beizhu);
				$("#home").val(xydata.home);
				$("#peixununit").val(xydata.peixununit);
				$("#ptype").val(xydata.ptype);
				$("#xuehao").val(xydata.xuehao);
				$("#zhengzhi").val(xydata.zhengzhi);
				$("#pic").attr("src","uploader/xueyuanimg/"+$idcard+".jpg");
			}
		});
	}else{
		$.xalert("输入有误，请检查！");
	}
}
function getuppic(){
	initpic()
	getxueyuaninfo()
}
function initpic(){
	
	$('#pic_upload').show().uploadify({
        'swf'      :'uploadify/uploadify.swf',
        'uploader':'pxy_bm',
        'fileTypeExts': '*.bmp',
        'fileSizeLimit': '1MB',
        'formData'     : {
			'type' : 'pic','idcard':$("#idcard").val()
		},
		'onUploadSuccess':function(file,data,response){
			$("#pic").attr("src","uploader/xueyuanimg/"+data);
		}
    });
}
function qr(){
	var puname=$("#puname").val();var ptype=$("#ptype").val();
	$.xconfirm("确认 "+ptype+" "+puname+" 报名?",function(data){
		if(data){
			var idcard=$("#idcard").val();	var minzu=$("#minzu").val();	var zhiwu=$("#zhiwu").val();var home=$("#home").val();
			var mphone=$("#mphone").val();	var zhicheng=$("#zhicheng").val();	var workunit=$("#workunit").val();	var zhuanye=$("#zhuanye").val();var peixununit=$("#peixununit").val();
			var address=$("#address").val();	var wenhua=$("#wenhua").val();	var zhengshuid=$("#zhengshuid").val();	var beizhu=$("#beizhu").val();	var pid=$("#pid").val();
			var zhengzhi=$("#zhengzhi").val();var xuehao=$("#xuehao").val();
			if(puname.length<2||idcard.length!=18||minzu.length<2||mphone.length!=11||workunit.length<1||address.length<1||ptype==""){
				$.xalert("请确保信息正确完整！");
				return false;
			}
			if(!IdCardValidate(idcard)){
				$.xalert("身份证信息不合法，请检查后重新输入！");
				return false;
			}
			if(IdCard(idcard,3)>59){
				$.xconfirm("该生年龄可能超限，是否继续?",function(data){
					if(data){
						//$.xloading(1);
						$.post("pxy_bm",{ptype:ptype,xuehao:xuehao,zhengzhi:zhengzhi,
								puname:puname,			idcard:idcard,			minzu:minzu,			zhiwu:zhiwu,			mphone:mphone,			zhicheng:zhicheng,
								workunit:workunit,			zhuanye:zhuanye,			address:address,			wenhua:wenhua,			zhengshuid:zhengshuid,
								pid:pid,			beizhu:beizhu,			type:"add",						home:home,						peixununit:peixununit
							},function(data){
								if(data==1){
									$.xalert("报名成功！");
									//$("#puname").val("");$("#idcard").val("");$("#minzu").val("");$("#zhengshuid").val("无");$("#mphone").val("")
								}else{
									$.xalert("报名失败，可能该学员已报名！");
									//$("#puname").val("");$("#idcard").val("");$("#minzu").val("");$("#zhengshuid").val("无");$("#mphone").val("")
								}
						}).error(function(){
							if(timeout){ //清除定时器
							    clearTimeout(timeout);
							    timeout=null;
							}
							qr();
						});}
				});
			}else{
				//$.xloading(1);
				var timeout=setTimeout(function(){
    					qr();
    				},5000 //超时时间，考虑到网络问题，5秒还是比较合理的
    			);
				$.post("pxy_bm",{ptype:ptype,xuehao:xuehao,zhengzhi:zhengzhi,
						puname:puname,			idcard:idcard,			minzu:minzu,			zhiwu:zhiwu,			mphone:mphone,			zhicheng:zhicheng,
						workunit:workunit,			zhuanye:zhuanye,			address:address,			wenhua:wenhua,			zhengshuid:zhengshuid,
						pid:pid,			beizhu:beizhu,			type:"add",						home:home,						peixununit:peixununit
					},function(data){
						if(timeout){ //清除定时器
    					    clearTimeout(timeout);
    					    timeout=null;
    					}
						//$.xloading(0);
						if(data==1){
							$.xalert("报名成功！");
							//$("#puname").val("");$("#idcard").val("");$("#minzu").val("");$("#zhengshuid").val("无");$("#mphone").val("")
						}else{
							$.xalert("报名失败，可能该学员已报名！");
							//$("#puname").val("");$("#idcard").val("");$("#minzu").val("");$("#zhengshuid").val("无");$("#mphone").val("")
						}
				}).error(function(){
					if(timeout){ //清除定时器
					    clearTimeout(timeout);
					    timeout=null;
					}
					qr();
				});
			}
		}
	});

}

function IdCard(UUserCard,num){if(num==1){     //获取出生日期
	       birth=UUserCard.substring(6, 10) + "-" + UUserCard.substring(10, 12) + "-" + UUserCard.substring(12, 14);return birth;
	   }if(num==2){   //获取性别
	       if (parseInt(UUserCard.substr(16, 1)) % 2 == 1) {	           //男
	     return "男";	       } else {	           //女
	     return "女";	       }	   }	   if(num==3){	        //获取年龄
	        var myDate = new Date();	        var month = myDate.getMonth() + 1;	        var day = myDate.getDate();	        var age = myDate.getFullYear() - UUserCard.substring(6, 10) - 1;
	        if (UUserCard.substring(10, 12) < month || UUserCard.substring(10, 12) == month && UUserCard.substring(12, 14) <= day) {
	            age++;
	        }	  return age;	 }	}

var xxf={
		temp:"",
		fun:function(t){
			if(t.value!=xxf.temp&&t.value!=""){
				xxf.temp=t.value;
				id=t.id;
				$.xxpost("pxy_bm",{type:"unit",str:t.value},function(data){
					$("#"+id).xautocomplete(JSON.parse(data));
					if(data=="[]"){
						$("#XAUTOCOMPLETE").remove();
					}
				});
			}
		},
		out:function(t){
			console.log(t);
		}
	}
</script>
</head>
<body>
<object classid="clsid:E6E0A751-541A-4855-9A8D-35EB7122C950" id="SynIDCard1" codeBase="SynIDCard.Cab#version=1,0,0,1" width="0" height="0">
  <param name="_Version" value="65536">
  <param name="_ExtentX" value="635">
  <param name="_ExtentY" value="582">
  <param name="_StockProps" value="0">
</object>
<form method="POST" action="--WEBBOT-SELF--" name="form1" enctype="multipart/form-data" >
<table border="0" align="center" cellpadding="0" cellspacing="1px" style="background-color:#bbb;margin:0 auto;">
	<tr><td colspan="4" align="center" valign="middle" bgcolor="#FFFFFF">报名表[*号必填选项]</td></tr>
	<tr>
	    <td bgcolor="#FFFFFF"><strong>班级</strong></td><td bgcolor="#FFFFFF" style="font-size: 12px;">{{$pname}}<input type="hidden" id="pid" name="pid" value="{{$pid}}"></td>
		<td bgcolor="#FFFFFF"><strong>培训单位<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF">
			<select id="peixununit">
				<?php foreach (explode(",",gconf('web', 'peixununit')) as $row){?>
					<option value="<?php echo $row;?>"><?php echo $row;?></option>
				<?php }?>
			</select>
		</td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF"><strong>姓名<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF"><input type="text" name="puname" id="puname"></td>
		<td bgcolor="#FFFFFF"><strong>民族<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF">
			<select id="minzu">
				<?php foreach (explode(",",gconf('web', 'minzu')) as $row){?>
					<option value="<?php echo $row;?>"><?php echo $row;?></option>
				<?php }?>
			</select>
		</td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF"><strong>身份证<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF" ><input type="text" name="idcard" id="idcard"><input type="button" id="serch" name="serch" value="查询" style="height: 23px;width:40px;padding:0px;"/></td>
		<td bgcolor="#FFFFFF"><strong>家庭地址</strong></td><td bgcolor="#FFFFFF"><input type="text" name="home" id="home" value="无"></td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF"><strong>职务<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF">
			<select id="zhiwu">
				<option value="无">无</option>
				<?php foreach (explode(",",gconf('web', 'zhiwu')) as $row){?>
					<option value="<?php echo $row;?>"><?php echo $row;?></option>
				<?php }?>
			</select>
			<select id="ptype"><option value="">选择人员类型</option>
				<?php foreach (explode(",",gconf('web', 'ptype')) as $row){?>
					<option value="<?php echo $row;?>"><?php echo $row;?></option>
				<?php }?>
			</select>
		</td>
		<td bgcolor="#FFFFFF"><strong>手机号码<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF"><input type="text" name="mphone" id="mphone"></td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF"><strong>职称<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF">
		<select id="zhicheng">
				<option value="无">无</option>
				<?php foreach (explode(",",gconf('web', 'zhicheng')) as $row){?>
					<option value="<?php echo $row;?>"><?php echo $row;?></option>
				<?php }?>
			</select>
		</td>
		<td bgcolor="#FFFFFF"><strong>单位名称<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF"><input type="text" name="workunit" id="workunit" AUTOCOMPLETE="off" onkeyup="xxf.fun(this)"></td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF"><strong>专业<span class="xxf_red">*</span></strong></td><td bgcolor="#FFFFFF">
			<select id="zhuanye">
				<option value="无">无</option>
				<?php foreach (explode(",",gconf('web', 'zhuanye')) as $row){?>
					<option value="<?php echo $row;?>"><?php echo $row;?></option>
				<?php }?>
			</select>
		</td><td bgcolor="#FFFFFF"><strong>单位地址<span class="xxf_red">*</span></strong></td>
		<td bgcolor="#FFFFFF">
			<input type="text" name="address" id="address" >
		</td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF"><strong>学历<span class="xxf_red">*</span></strong></td>
		<td bgcolor="#FFFFFF">
			<select id="wenhua">
				<option value="无">无</option>
				<?php foreach (explode(",",gconf('web', 'wenhua')) as $row){?>
					<option value="<?php echo $row;?>"><?php echo $row;?></option>
				<?php }?>
			</select>
		</td>
		<td bgcolor="#FFFFFF"><strong>证书编号</strong></td>
		<td bgcolor="#FFFFFF"><input type="text" name="zhengshuid" id="zhengshuid" value="无"></td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF"><strong>政治面貌</strong></td>
		<td bgcolor="#FFFFFF">
			<select id="zhengzhi">
				<option value="无">无</option>
				<?php foreach (explode(",",gconf('web', 'zhengzhi')) as $row){?>
					<option value="<?php echo $row;?>"><?php echo $row;?></option>
				<?php }?>
			</select>
		</td>
		<td bgcolor="#FFFFFF"><strong>学号</strong></td>
		<td bgcolor="#FFFFFF"><input type="text" name="xuehao" id="xuehao" value="无"></td>
	</tr>
	<tr>
		<td bgcolor="#FFFFFF"><strong>备注</strong></td>
		<td bgcolor="#FFFFFF" colspan="3">
			<textarea id="beizhu" style="width:100%;height:100px;">无</textarea>
		</td>
	</tr>
	<tr>
		<td colspan="3" bgcolor="#FFFFFF" height="120px;" valign="top">
			照片路径[刷身份证后点击按钮添加照片]：<br><input id="tpic" value="" style="width: 350px;">
			<br><div id="queue"></div><input id="pic_upload" name="pic_upload" type="file" style="display: none" />
		</td>
		<td bgcolor="#FFFFFF" align="center" valign="top" style="font-size: 12px;">
			<img id="pic" src="" width="102px" height="126px" alt="照片*">
		</td>
	</tr>
	<tr>
		<td colspan="4" bgcolor="#FFFFFF">端口号：<input type="text" name="Port" size="4" value="1001">
          <!-- <input type="button" value="设置端口" name="SetPortBtn"> -->
          <input type="button" value="读身份证信息" name="ReadCardBtn">
          <input type="text" id="RETSTR" name="RETSTR">
          <br><br>
          <input type="button" value="确认报名" id="sub" name="sub" onClick="qr()">
         </td>
	</tr>
</table>
</form>
</body>
</html>